<%--
  Created by IntelliJ IDEA.
  author: Jsonor
  date: 2018/4/19 14:35
  description: Description
--%>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="description" content="我要买车-按车型" />
  <title>我要买车-按车型</title>
  <link type="text/css" rel="stylesheet" href="css/global.css" />
  <script src="js/jquery-1.7.min.js" type="text/javascript"></script>
  <script src="js/jQselect.js" type="text/javascript"></script>
  <script>
    $(document).ready(function() {
      $("#c").selectbox();
      $("#c1").selectbox();
      $("#c2").selectbox();
    });
  </script>
  <!--[if lt IE 7]>
  <script type="text/javascript" src="js/unitpngfix.js"></script>
  <![endif]-->

  <script type="text/javascript">
    function firstPage(){
      var pageNum=document.getElementById("pageNum").value;
      if(1==pageNum){
        alert("亲，已经是首页了");
      }else{
        window.location.href="<%=request.getContextPath()%>/Items/queryAllItems.action?pageNum="+1;
      }
    }
    function prePage(){
      var pageNum=document.getElementById("pageNum").value;
      pageNum--;
      window.location.href="<%=request.getContextPath()%>/Items/queryAllItems.action?pageNum="+pageNum;
    }
    function nextPage(){
      var pageNum=document.getElementById("pageNum").value;
      pageNum++;
      window.location.href="<%=request.getContextPath()%>/Items/queryAllItems.action?pageNum="+pageNum;
    }
    function lastPage(){
      var pageNum=document.getElementById("pageNum").value;
      var totalPage=document.getElementById("totalPage").value;
      if(pageNum==totalPage){
        alert("亲，已经是尾页了");
      }else{
        window.location.href="<%=request.getContextPath()%>/Items/queryAllItems.action?pageNum="+totalPage;
      }
    }
  </script>
  <style>
    ul.pagination {
      display: inline-block;
      padding: 0;
      margin: 0;
    }

    ul.pagination li {display: inline;}

    ul.pagination li a {
      color: black;
      float: left;
      padding: 8px 16px;
      text-decoration: none;
      transition: background-color .3s;
      border: 1px solid #ddd;
    }

    ul.pagination li a.active {
      background-color: #4CAF50;
      color: white;
      border: 1px solid #4CAF50;
    }

    ul.pagination li a:hover:not(.active) {background-color: #ddd;}
  </style>

</head>

<body>
<%@include file="menu.jsp"%>
<div class="container">
  <div class="nav"><a href="#">首页</a> &gt; 我要买车</div>
  <div class="con_buy">
    <div class="title"></div>
    <div class="detail">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_sear">
      </table>
      <div class="search_list">
        <c:forEach var="n" items="${pi.list}">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_list">
          <tr>
            <td width="135"><img src="${pageContext.request.contextPath}/${n.carimages}" width="105" height="70"></td>
            <td width="725"><div class="title_car"><a href="......." class="name">${n.carname}</a>
              <p class="price">价格：<span class="red">￥${n.caroriginalprice}</span></p>
            </div>
              <div class="detail_car">${n.carintroduce}</div></td>
            <%--<a href="${pageContext.request.contextPath}/add.do" class="green_a">加入购物车>></a>--%>
            <td align="right"><a href="${pageContext.request.contextPath}/shopcar.do?carid=${n.carid}" class="green_a">去看看>></a></td>

          </tr>
        </table>
        </c:forEach>

      </div>
      <%--分页--%>
      <c:choose>
        <c:when test="${pi.pages<10}">
          <c:set var="begin" value="1"/>
          <c:set var="end" value="${pi.pages}"/>
        </c:when>
        <c:otherwise>
          <c:set var="begin" value="${pi.pageNum-5}"/>
          <c:set var="end" value="${pi.pageNum+4}"/>
          <c:if test="${begin<1}">
            <c:set var="begin" value="1"/>
            <c:set var="end" value="${pi.pages}"/>
          </c:if>
        </c:otherwise>
      </c:choose>
      <span style="color:#666;">第${pi.pageNum}页/共${pi.pages}页</span>
      <%--<div>
        <input type="hidden" id="pageNum" value="${itemsList.getPageNum()}">
        <input type="hidden" id="totalPage" value="${itemsList.getPages()}">
        <span onclick="firstPage()">首页</span> <span onclick="prePage()">上一页</span>
        <span onclick="nextPage()">下一页</span> <span onclick="lastPage()">尾页</span>
      </div>--%>
      <div>
        <div>
          <ul class="pagination">
            <c:if test="${pi.pageNum ne 1}">
              <li>
                <a href="${pageContext.request.contextPath}/showcar.do?page=${pi.firstPage}"><span>首页</span></a>
              </li>
              <li>
                <a href="${pageContext.request.contextPath}/showcar.do?page=${pi.prePage}"><span>上一页</span></a>
              </li>
            </c:if>
            <c:forEach var="num" begin="${begin}" end="${end}">
              <c:choose>
                <c:when test="${num eq pi.pageNum}">
                  <li>
                    <a><span>${num}</span></a>
                  </li>
                </c:when>
                <c:otherwise>
                  <li>
                    <a href="${pageContext.request.contextPath}/showcar.do?page=${num}"><span>${num}</span></a>
                  </li>
                </c:otherwise>
              </c:choose>
            </c:forEach>
            <c:if test="${pi.pageNum ne pi.pages}">
              <li>
                <a href="${pageContext.request.contextPath}/showcar.do?page=${pi.nextPage}"><span>下一页</span></a>
              </li>
              <li>
                <a href="${pageContext.request.contextPath}/showcar.do?page=${pi.lastPage}"><span>尾页</span></a>
              </li>
            </c:if>
          </ul>
        </div>
      </div>
      <%--<center>
        <c:if test="${page.currentpage != 1 }">
          <a href="${pageContext.request.contextPath }?currentpage=${page.currentpage-1}">上一页</a>
        </c:if>

        <!-- 表里中间位置   ${page.totalpage }-->
        <c:forEach var="i" begin="1" end="${page.totalpage}" step="1">
          &lt;%&ndash;  <c:forEach var="i" begin="${i}" end="${(i+8)>page.totalpage?page.totalpage:(i+8) }" step="1">   &ndash;%&gt;
          <!--  当页数过多时，显示部分页数，随着页数的增大，隐藏前边页数，显示后边的页数 -->
          <c:if test="${page.currentpage == i}">
            ${i }
          </c:if>
          <c:if test="${page.currentpage !=i}">
            <a href="${pageContext.request.contextPath}?currentpage=${i}">${i}</a>
          </c:if>
        </c:forEach>

        <c:if test="${page.totalpage != page.currentpage}">
          <a href="${pageContext.request.contextPath }?currentpage=${page.currentpage+1}">下一页</a>
        </c:if>

        <br/>
        第${page.currentpage}页/总${page.totalpage}页
      </center>--%>
      <%--<table cellspacing="0" cellpadding="0" border="0" width="100%"  >
        <tbody>
        <tr>
          <td>&nbsp;</td>
          <td align="right"><ul class="page-nav">
            <li class="curr-page"><a href="#">1</a></li>
            <li><a href="#">2</a></li>
            <li><a href="#">3</a></li>
            <li><a href="#">4</a></li>
            <li><a href="#">5</a></li>
            <li>...</li>
            <li> <a href="#" class="arr_nexr">下一页</a> </li>
          </ul></td>
        </tr>
        </tbody>
      </table>--%>
    </div>
  </div>
</div>
<%@ include file="bottom.jsp" %>

</body>
</html>

